<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>array unique</title>
</head>
<body>
    
    <script>
    
        {
            // 对象去重法 

            let ary = [1,2,3,1,2,1,1,2,2,1,4,5,4,4,5,5,4,1,5,4,3,3,2,4,5];

            Array.prototype.unique = function () {
                let obj = {};
                for(let i=0;i<this.length;i++){
                    let ele = this[i];
                    if(typeof obj[ele] != 'undefined'){
                        this[i] = this[this.length - 1];
                        this.length--;
                        i--;
                        continue;
                    }
                    obj[ele] = ele;
                }
                obj = null;
                return this;
            }

            console.log(ary.unique().sort());

        }
    
    </script>
</body>
</html>